package org.framework.superutil.j2se;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @Title: RequestContextUtils.java .<br>
 * @Package org.framework.superutil.j2se .<br>
 * @Description: httpRequest上下文工具类 .<br>
 * @author 郑成功 .<br>
 * @email a876459952@qq.com .<br>
 * @date 2018-6-19 上午10:23:31.<br>
 * @version V1.0.<br>
 */
public class RequestContextUtils {
	
	/**
	 * @Description: 获取请求 .<br>
	 * @author 郑成功 .<br>
	 * @date 2018-6-19 上午10:24:31.<br>
	 */
	public static HttpServletRequest getRequest() {
       return getRequestAttributes().getRequest();
    }

	/**
	 * @Description: 获取session .<br>
	 * @author 郑成功 .<br>
	 * @date 2018-6-19 上午10:24:46.<br>
	 */
    public static HttpSession getSession() {
        return getRequest().getSession();
    }

    /**
     * @Description: 获取请求参数 .<br>
     * @author 郑成功 .<br>
     * @date 2018-6-19 上午10:25:04.<br>
     */
    public static ServletRequestAttributes getRequestAttributes() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
    }

    /**
     * @Description: 获取Servlet上下文 .<br>
     * @author 郑成功 .<br>
     * @date 2018-6-19 上午10:25:20.<br>
     */
    public static ServletContext getServletContext() {
        return ContextLoader.getCurrentWebApplicationContext().getServletContext();
    }

}
